*******************************************************************************
* Load media data
*******************************************************************************

use dataset_media, clear

*******************************************************************************
* Keep only used
*******************************************************************************

keep state district articleurl excerpt

*******************************************************************************
* Re-format district
*******************************************************************************

replace district = subinstr(district, state, "", 1)

*******************************************************************************
* Format for table output
*******************************************************************************

replace excerpt = "\truncate{\linewidth}{" + excerpt + "} "
replace articleurl = "\truncate{\linewidth}{\url{" + articleurl + "}}"

replace state = "CA" if state == "California"
replace state = "MS" if state == "Mississippi"
replace state = "NY" if state == "New York"
replace state = "PA" if state == "Pennsylvania"
replace state = "VA" if state == "Virginia"

replace district = subinstr(district, " ", "", 10)

*******************************************************************************
* Output table
*******************************************************************************

levelsof state, local(levels)
foreach l of local levels {
	
	preserve
	
	keep if state == "`l'"

	drop state
	
	#delimit;

	listtex 
		using "_output/tableS8_`l'.tex"
		,
			replace 
			type 
			rstyle(tabular) 	
			head(
				\begin{tabular}{
					|p{0.14\textwidth}
					|p{0.4\textwidth}
					|p{0.4\textwidth}|
				}
				\hline
				District
				& 
				URL
				& 
				Excerpt
				\\
				\hline
			)
			foot("\hline\end{tabular}")
			;
			
	#delimit cr
	
	restore
	
}

*******************************************************************************
* End
*******************************************************************************
